<template>
  <div>
    <search @add="handleOpenDialog" @search="handleSearchByKeyword" />
    <ms-table
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      :table-props="tableProps"
      :data-api="dataUrl"
      :pagination="false"
      ref="dataTable"
      row-key="depId"
    >
      <el-table-column label="操作" slot="tool">
        <template slot-scope="scope">
          <el-button
            size="mini"
            v-permission="['department:save']"
            @click="handleOpenDialog(scope.row.depId)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelDep(scope.row.depId)"
            v-permission="['department:del']"
            >删除</el-button>
        </template>
      </el-table-column>
    </ms-table>
    <info ref="infoForm" :title="title" :dialog-visible="dialog1" :form-id="formId" @dataFresh="handleCanleDialog" @close="handleCanleDialog" />
  </div>
</template>

<script>
import { MsTable } from '@/common/table'
import Info from './Info'
import Search from './Search'
import { deleteDep } from '@/api/sys/dep'
import common from '@/mixins/common'
export default {
  components: {
    MsTable,
    Info,
    Search
  },
  mixins: [common],
  data() {
    return {
      tableProps: [
        { index: 'name', label: '部门名称' },
        { index: 'status', label: '部门状态' },
        { index: 'createTime', label: '创建时间' }
      ],
      dataUrl: '/sys/department/list',
      mainTitle: '部门管理'
    }
  },
  methods: {
    handleDelDep(id) {
      deleteDep(id).then((res) => {
        console.log(res)
      })
    }
  }
}
</script>
